{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Practice Problem - Monte-Carlo Error Propagation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You have likely encountered the concept of propagation of uncertainty before (see [the usual rules here](http://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas)). The idea is that given measurements with uncertainties, we can find the uncertainty on the final result of an equation.\n", "\n", "For example, let us consider the following equation:\n", "\n", "$$F = \\frac{G~M_1~M_2}{r^2}$$\n", "\n", "which gives the gravitational force between two masses $M_1$ and $M_2$ separated by a distance $r$.\n", "\n", "Let us now imagine that we have two masses:\n", "\n", "$$M_1=(40\\pm0.05)\\times10^4\\,\\mathrm{kg}$$\n", "\n", "and\n", "\n", "$$M_2=(30\\pm0.1)\\times10^4\\,\\mathrm{kg}$$\n", "\n", "separated by a distance:\n", "\n", "$$r=3.2\\pm0.01\\,\\mathrm{m}$$\n", "\n", "where the uncertaintes are normally distributed (Gaussian measurement uncertainties).\n", "\n", "We also know:\n", "\n", "$$G = 6.67384\\times10^{-11}\\,\\mathrm{m}^3\\,\\mathrm{kg}^{-1}\\,\\mathrm{s}^{-2}$$\n", "\n", "(exact value, no uncertainty).\n", "\n", "Use the [standard error propagation rules](http://en.wikipedia.org/wiki/Propagation_of_uncertainty#Example_formulas) to determine the resulting force and uncertainty in your script (you can just derive the equation by hand and implement it in a single line in your code).\n", "\n", "Now, we can try using a **Monte-Carlo** technique instead. The idea behind Monte-Carlo techniques is to generate many possible solutions using random numbers and using these to look at the overall results. In the above case, you can propagate uncertainties with a Monte-Carlo method by doing the following:\n", "\n", "* randomly sample 1000000 times values of $M_1$, $M_2$, and $r$ using the means and standard deviations given above\n", "\n", "* compute the gravitational force for each set of values\n", "\n", "You should do this with Numpy arrays, and **without any loops**. You should then get an array of 1000000 different values for the forces.\n", "\n", "Make a plot of the normalized histogram of these values of the force, and then overplot a Gaussian function with the mean and standard deviation derived with the standard error propagation rules. Make sure that you pick the range of x values in the plot wisely, so that the two distributions can be seen. Make sure there are also a sensible number of bins in the histogram so that you can compare the shape of the histogram and the Gaussian function. The two distributions should agree pretty well." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "# Your solution here\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now repeat the experiment above with the following values:\n", "\n", "$$M_1=(40\\pm2)\\times10^4\\,\\mathrm{kg}$$\n", "$$M_2=(30\\pm10)\\times10^4\\,\\mathrm{kg}$$\n", "$$r=(3.2\\pm1.0)\\,\\mathrm{m}$$\n", "\n", "and as above, produce a plot.\n", "\n", "In this case, which method do you think is more accurate? Why? What do you think are the advantages of using a Monte-Carlo technique?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solution" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "# your solution here\n" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" } }, "nbformat": 4, "nbformat_minor": 1 }